using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace JBORPG.Net
{
    public class Serializer
    {
        public static String SerializeObject(Object o)
        {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(ms, o);
            return Convert.ToBase64String(ms.ToArray());
        }

        public static Object DeSerializeObject(String d)
        {
            Byte[] bytes = Convert.FromBase64String(d);
            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();
            ms.Write(bytes, 0, bytes.Length);
            ms.Seek(0, SeekOrigin.Begin);

           return bf.Deserialize(ms);
        }
    }
}
